<?php
class Mapper_User extends DBTable{
	
	public function __construct(Database $db){
		parent::__construct($db, "user");
	}
	
	public function __get($var){
		return $this->get($var);
	}
	
	public function get($user_id){
		$query	=	"
					SELECT
						*
					FROM
						user
					WHERE
						user_id = :user_id;";
		$stmt = $this->db->prepare($query);
		$stmt->bindParam(":user_id",$user_id);
		return $stmt->fetchObjectOnce('User');
	}
	
	public function getByLogin($nick, $pass){
		$query	=	"SELECT
						*
					FROM
						user
					WHERE
						user_nick = :nick
					AND user_pass = :pass";
		$stmt = $this->db->prepare($query);
		$stmt->bindParam(":nick",$nick);
		$stmt->bindValue(":pass",md5($pass));
		return $stmt->fetchObjectOnce('User');
	}
	
	public function getAll(){
		$query	=	"SELECT
						*
					FROM
						user";
		$stmt = $this->db->prepare($query);
		return $stmt->fetchObjectAll('User');
	}
}